<!DOCTYPE html>
<html>

<head lang="en">
    <title>骡窝日报</title>
    <meta charset="utf-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

    <link rel="stylesheet" href="/js/bootstrap-4.1.1-dist/css/bootstrap.min.css">
    <script src="/js/jquery/jquery.min.js"></script>
    <script src="/js/bootstrap-4.1.1-dist/js/bootstrap.min.js"></script>
    <link rel="stylesheet" href="/css/font/css/font-awesome.min.css"/>
    <link rel="stylesheet" href="/css/reset.css"/>
    <link rel="stylesheet" href="/css/news.css"/>
    <script src="/js/plugins/jrender/jrender.min.js"></script>
    <link rel="stylesheet" href="/js/plugins/dialog2/dialog.css"/>
    <script src="/js/plugins/dialog2/dialog.min.js"></script>
    <script src="/js/common.js"></script>
    <script type="text/javascript" src="/js/plugins/form/jquery.form.js"></script>

    <script>
        $(function () {
            var judge = 1;
            //获取装载数据的input框
            var currentInput = $("#currentPage");
            //创建用于存储日报的数组
            var dailyArr = [];
            //总页数
            var pages = 1;

            //获取日报数据的方法
            function query() {
                //获取当前页的值
                var currentPage = currentInput.val();
                $.get('/dailies/list', {currentPage: currentPage, pageSize: 4}, function (data) {
                    //合并两个数组到第一个参数数组上
                    $.merge(dailyArr, data.list);
                    //用于渲染时循环,循环时是取list的属性出来
                    var json = {
                        list: dailyArr
                    };
                    //渲染数据
                    $(".newsList").renderValues(json, {
                        getHref: getHref
                    });
                    //设置总页数
                    pages = data.pages;
                });
                //当前页input框+1
                currentInput.val(parseInt(currentPage) + 1);
            }

            //默认查询第一页的数据
            query();

            //当页面滚动条变化时，执行的函数
            $(window).scroll(function () {
                if ($(document).scrollTop() + $(window).height() >= $(document).height() - 5) {
                    var currentPage = currentInput.val();
                    if (judge == 1) {
                        //判断是否小于或等于最后一页,如果是就去查询
                        if (currentPage <= pages) {
                            query();
                        }
                        else {
                            $(document).dialog({
                                type: 'notice',
                                infoText: '已经到底了!',
                                autoClose: 2500,
                                position: 'bottom'  // center: 居中; bottom: 底部
                            });
                        }
                    }
                }
            });
        })
    </script>

</head>

<body>


<div class="search-head">
    <div class="row nav-search">
        <div class="col-2">
            <a href="index.html">
                <span><i class="fa fa-chevron-left fa-2x"></i></span>
            </a>
        </div>
        <div class="col-10">
            <div class="input-group-sm search">
                <input class="form-control searchBtn" placeholder="搜索资讯">
            </div>
        </div>
    </div>
</div>

<input type="hidden" name="currentPage" id="currentPage" value="1">
<div class="container news">

    <div class="news">
        <h6 class="news-title">骡窝日报</h6>
        <div class="newsList">
            <div class="row" render-loop="list">
                <div class="col-6">
                    <a data-href="/newsContent.html?id=" data-id="2" render-key="list.id" render-fun="getHref">
                        <img class="rounded" width="100%" height="110px" render-src="list.coverUrl">
                    </a>
                    <div class="caption">
                        <p>
                            <span></span>
                            <i class="fa fa-heart-o"></i>
                        </p>
                        <a data-href="/newsContent.html?id=" render-key="list.id" render-fun="getHref">
                            <p render-html="list.title"></p>
                        </a>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

</body>
</html>